package com.anjubao.parking.municipal.parkingrecord.util;

import com.anjubao.parking.municipal.parkinglot.dto.EntryEnterDTO;
import com.anjubao.parking.municipal.parkinglot.dto.EntryLeaveDTO;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingLotDto;
import com.anjubao.parking.municipal.parkingrecord.model.ParkingRecord;

/**
 * @author anjubao
 */
public class DtoTransfer {
    /**
     * 封装进场请求参数到entity中
     *
     * @param parkingLotDTO
     * @return ParkingRecord
     */
    public static ParkingRecord parkingLotDTO2EnterRecord(ParkingLotDto parkingLotDTO, EntryEnterDTO entryEnterDTO) {
        ParkingRecord parkingRecord = new ParkingRecord();
        ParkingRecord parkingLot = parkingLotToRecord(parkingRecord, parkingLotDTO);
        //赋请求参数
        parkingLot.setRemoteParkingRecordId(entryEnterDTO.getLocalRecordId());
        parkingLot.setCardId(entryEnterDTO.getCardId());
        parkingLot.setSystemType(parkingLotDTO.getType());
        parkingLot.setCustomerName(entryEnterDTO.getCustomerName());
        parkingLot.setCustomerContactNumber(entryEnterDTO.getCustomerPhone());
        parkingLot.setEnterPort(entryEnterDTO.getEnterPortName());
        parkingLot.setEnterSnapshotUrl(entryEnterDTO.getEnterSnapshotUrl());
        parkingLot.setEnterTime(entryEnterDTO.getEnterDateTime());
        parkingLot.setParkingType(entryEnterDTO.getParkingType());
        parkingLot.setPlateNumber(entryEnterDTO.getPlateNumber());
        parkingLot.setVehicleType(entryEnterDTO.getVehicleType());
        parkingLot.setParkingDetectType(entryEnterDTO.getParkingDetectType());
        return parkingLot;
    }
    /**
     * 将车场信息封装到实体的方法
     *
     * @param parkingLotDTO
     * @return
     */
    private static ParkingRecord parkingLotToRecord(ParkingRecord parkingRecord, ParkingLotDto parkingLotDTO) {
        //赋车场信息参数
        parkingRecord.setParkingLotName(parkingLotDTO.getName());
        parkingRecord.setParkingLotProvinceId(parkingLotDTO.getProvinceId());
        parkingRecord.setParkingLotProvinceName(parkingLotDTO.getProvinceName());
        parkingRecord.setParkingLotCityId(parkingLotDTO.getCityId());
        parkingRecord.setParkingLotCityName(parkingLotDTO.getCityName());
        parkingRecord.setParkingLotDistrictId(parkingLotDTO.getDistrictId());
        parkingRecord.setParkingLotDistrictName(parkingLotDTO.getDistrictName());
        return parkingRecord;
    }

    /**
     * 封装出场请求参数到entity中
     *
     * @param parkingLotDTO
     * @return ParkingRecord
     */
    public static ParkingRecord parkingLotDTO2LeaveRecord(ParkingLotDto parkingLotDTO, EntryLeaveDTO entryLeaveDTO) {
        ParkingRecord entryLeave = parkingLotDTO2ParkingRecord(entryLeaveDTO);
        //封装车场信息
        return parkingLotToRecord(entryLeave, parkingLotDTO);
    }

    /**
     * 封装请求参数到entity中
     *
     * @param entryLeaveDTO
     * @return ParkingRecord
     */

    public static ParkingRecord parkingLotDTO2ParkingRecord(EntryLeaveDTO entryLeaveDTO) {
        //创建entity对象
        ParkingRecord parkingRecord = new ParkingRecord();
        //赋请求参数
        parkingRecord.setRemoteParkingRecordId(entryLeaveDTO.getLocalRecordId());
        //parkingRecord.setParkingRecordCode(entryLeaveDTO.getParkingRecordCode());
        parkingRecord.setCardId(entryLeaveDTO.getCardId());
        parkingRecord.setCustomerName(entryLeaveDTO.getCustomerName());
        parkingRecord.setSystemType(entryLeaveDTO.getSystemType());
        parkingRecord.setCustomerContactNumber(entryLeaveDTO.getCustomerPhone());
        parkingRecord.setEnterPort(entryLeaveDTO.getEnterPortName());
        parkingRecord.setEnterSnapshotUrl(entryLeaveDTO.getEnterSnapshotUrl());
        parkingRecord.setEnterTime(entryLeaveDTO.getEnterDateTime());
        parkingRecord.setParkingType(entryLeaveDTO.getParkingType());
        parkingRecord.setPlateNumber(entryLeaveDTO.getPlateNumber());
        parkingRecord.setVehicleType(entryLeaveDTO.getVehicleType());
        parkingRecord.setLeavePort(entryLeaveDTO.getLeavePortName());
        parkingRecord.setLeaveSnapshotUrl(entryLeaveDTO.getLeaveSnapshotUrl());
        parkingRecord.setLeaveTime(entryLeaveDTO.getLeaveTime());
        parkingRecord.setLeaveParkingDuration(entryLeaveDTO.getParkingDuration());
        parkingRecord.setFeeTotal(entryLeaveDTO.getFeeTotal());
        parkingRecord.setPaidTotal(entryLeaveDTO.getPaidTotal());
        parkingRecord.setDiscountTotal(entryLeaveDTO.getDiscountTotal());
        parkingRecord.setBatteryChargingDuration(entryLeaveDTO.getBatteryChargingDuration());
        parkingRecord.setIsBatteryCharged(entryLeaveDTO.getIsBatteryCharged());
        parkingRecord.setParkingDetectType(entryLeaveDTO.getParkingDetectType());

        return parkingRecord;
    }
}
